import request from '@/utils/request'
import wx from 'weixin-js-sdk'
// 获取所有用户的名称列表
export const getAllUserApi = () => {
  return request({
    url: '/getAllCustomerNameLists',
    method: 'POST'
  })
}

// 登录
export const loginApi = (data) => {
  return request({
    url: '/login',
    method: 'POST',
    data
  })
}

// 获取用户报告列表
export const getReportListApi = () => {
  return request({
    url: '/overView',
    method: 'POST'
  })
}

// 根据id获取报告详情
export const getReportDetailApi = (id) => {
  return request({
    url: '/getOverViewById',
    method: 'POST',
    data: {
      overview_id: id
    }
  })
}

// 根据id获取审线小结
export const getSummaryApi = (id) => {
  return request({
    url: '/summary',
    method: 'POST',
    data: {
      overview_id: id
    }
  })
}

// 根据id获取基本信息
export const getBasicInfoApi = (id) => {
  return request({
    url: '/baseInfo',
    method: 'POST',
    data: {
      overview_id: id
    }
  })
}

// 根据id获取产线基本信息
export const getLineBasicInfoApi = (id) => {
  return request({
    url: '/productionLineSetting',
    method: 'POST',
    data: {
      overview_id: id
    }
  })
}

// 根据id获取产线调整建议信息
export const getLineAdjustmentApi = (id) => {
  return request({
    url: '/suggestionForProductionlineAdj',
    method: 'POST',
    data: {
      overview_id: id
    }
  })
}

// 根据id获取产品推荐信息
export const getProductRecommendationApi = (id) => {
  return request({
    url: '/productRecommendations',
    method: 'POST',
    data: {
      overview_id: id
    }
  })
}

// 根据id获取工艺维护信息
export const getCraftMaintainApi = (id) => {
  return request({
    url: '/processMaintenances',
    method: 'POST',
    data: {
      overview_id: id
    }
  })
}

// 获取微信签名信息
export const getWeixinSignApi = (jsApiList) => {
  request({
    url: 'https://www.mahelei.com/index.php/Gm/Wechat/share',
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: {
      url: encodeURIComponent(window.location.href.split('#')[0])
    }
  }).then((res) => {
    weixinInit(res, jsApiList)
  })
}

// 微信配置
const weixinInit = (e, jsApiList) => {
  const data = e.data
  wx.config({
    debug: false,
    appId: data.appId,
    timestamp: data.timestamp,
    nonceStr: data.nonceStr,
    signature: data.signature,
    jsApiList
  })
  wx.ready(() => {
    wx.checkJsApi({
      jsApiList,
      success: (res) => {
        console.log(res)
      }
    })
  })
}
